﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Xml;
using System.Windows.Data;
using System.Windows;
using LIUS.Beta.FileSystem.PathFileSuffix;

namespace Kopain2
{

    /// <summary>This class is for handling the tree view data of the application.  It is really just a wrapper around DocumentList to make it INotifyPropertyChanged.
    /// </summary>
    class KopainTreeviewData  : INotifyPropertyChanged
    {

#region	Private properties.

        private KopainDocumentTree _nodeList;

        private static class PropertyName
        {
            public const string TheNodeList = "TheNodeList";
        }

#endregion	//	Private properties.

#region	Public properties.

        /// <summary>This property is the very data, the hierichal tree.
        /// </summary>
        internal KopainDocumentTree DocumentList
        {
            get
            {
                return _nodeList;
            }
        }

#endregion	//	Public properties.

#region	Constructors.

        internal KopainTreeviewData()
        {
            //_nodeList = new KopainDocumentList();
            //_nodeList.Add(new KopainDocument("BB", "A"));
            //_nodeList.Add(new KopainDocument("AA", "A"));
            //_nodeList[0].Children = new KopainDocumentList();
            //_nodeList[0].Children.Add(new KopainDocument("b", "B"));
            //_nodeList[0].Children.Add(new KopainDocument("c", "B"));
        }

#endregion	//	Constructors.

#region	Public methods.

        /// <summary>This method is used for createing a Binding to the xaml gui.  It is not used right now but kept as a reference for future implementations.
        /// </summary>
        /// <returns></returns>
        internal Binding CreateTheNodeListBinding()
        {
            Binding ret = new Binding();
            ret.Source = this;
            ret.Path = new PropertyPath(PropertyName.TheNodeList);
            return ret;
        }

        /// <summary>This method populates teh tree with the parameter.
        /// </summary>
        /// <param name="nodeList"></param>
        internal void Populate(KopainDocumentTree nodeList)
        {
            _nodeList = nodeList;
        }

        /// <summary>This method populates this treeview object.
        /// </summary>
        /// <param name="concept"></param>
        internal void Populate(KopainConcept.Concept concept)
        {
            _nodeList.Clear();
            //TODO:Populate with children too.
            foreach (KopainConcept.Concept.Note note in concept.NoteList)
            {
                _nodeList.Add(KopainDocument.CreateFile(null, Guid.NewGuid(), note.Title, note.FilenameSuffix));
            }
        }

        private static void Populate(KopainDocumentTree document, List<KopainConcept.Schemas.NoteType> noteList)
        {
            foreach (KopainConcept.Schemas.NoteType note in noteList)
            {
                document.Add(KopainDocument.CreateFile(null, Guid.NewGuid(), note.title, new FilenameSuffix( note.file, AllowPeriod.Yes, RequireSuffix.No)));
            }
        }

#endregion	//	Public methods.

#region	Private methods.

        private void Raise_PropertyChanged(string propertyname)
        {
            System.ComponentModel.PropertyChangedEventHandler temp = PropertyChanged;
            if (temp != null)
            {
                temp(this, new System.ComponentModel.PropertyChangedEventArgs(propertyname));
            }
        }

#endregion	//	Private methods.

#region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

#endregion

    }
}
